package com.klb.action.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.klb.model.BbsArticle;
import com.klb.service.admin.impl.ArticleServiceAdminImpl;
import com.klb.service.admin.impl.BlockServiceAdminImpl;
import com.klb.tools.Sessions;
import com.klb.tools.Tools;
import com.opensymphony.xwork2.ActionSupport;

/**
 * Created by fujia on 2016/7/2.
 */
public class ArticleActionAdmin extends ActionSupport {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private ArticleServiceAdminImpl articleServiceAdmin;
    private BlockServiceAdminImpl blockServiceAdmin;


	public void setArticleServiceAdmin(ArticleServiceAdminImpl articleServiceAdmin) {
		this.articleServiceAdmin = articleServiceAdmin;
	}

	public void setBlockServiceAdmin(BlockServiceAdminImpl blockServiceAdmin) {
		this.blockServiceAdmin = blockServiceAdmin;
	}



	@Override
    public String execute() throws Exception {
        HttpServletRequest request = ServletActionContext.getRequest();

        if (!Tools.objectIsNullOrNot(request.getParameter("block"))){
            int blockId = Integer.parseInt(request.getParameter("block"));
            List<BbsArticle> articles = this.articleServiceAdmin.getAllBlockArticles(blockId);
            String title = this.blockServiceAdmin.getTitleById(blockId);

            Sessions.setSession("articles", articles);
            Sessions.setSession("blockName", title);

            return SUCCESS;
        }

        return ERROR;
    }


}
